// 添加loading动画
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.6;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes wave {
  0% {
    transform: translateY(0);
  }
  33% {
    transform: translateY(-6px);
  }
  66% {
    transform: translateY(6px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes zoomIn {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

// SVG 图标定义
$icon-close: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E";
$icon-confirm: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E";
$icon-info: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z'/%3E%3C/svg%3E";
$icon-success: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'/%3E%3C/svg%3E";
$icon-warning: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z'/%3E%3C/svg%3E";
$icon-error: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E";
$icon-image: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E";

// 弹窗容器
.dialog-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s ease-out;
}

// 遮罩层
.dialog-mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: -1;
}

// 弹窗主体
.dialog-wrapper {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  max-width: 90%;
  animation: slideIn 0.3s ease-out;
  position: relative;

  &.dialog-media {
    background: transparent;
    box-shadow: none;
    max-height: 95vh;
    animation: zoomIn 0.3s ease-out;

    .dialog-header {
      background: rgba(0, 0, 0, 0.5);
      border-bottom: none;
      border-radius: 8px 8px 0 0;

      .dialog-title {
        color: #fff;
      }

      .dialog-close {
        color: #fff;

        &:hover {
          color: #ddd;
        }
      }
    }

    .dialog-content {
      padding: 0;
      border-radius: 8px;
      overflow: hidden;
      width: 100%;
      height: 100%;

      img, video {
        display: block;
        width: 100%;
        height: auto;
        max-height: 95vh;
        margin: 0 auto;
        object-fit: contain;
      }

      video {
        background: #000;
      }
    }

    .media-close {
      position: absolute;
      top: 16px;
      right: 16px;
      width: 36px;
      height: 36px;
      line-height: 36px;
      text-align: center;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 50%;
      color: #fff;
      font-size: 24px;
      cursor: pointer;
      transition: all 0.3s;
      z-index: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      backdrop-filter: blur(4px);

      &:hover {
        background: rgba(0, 0, 0, 0.7);
        transform: rotate(90deg);
      }
    }
  }
}

// 弹窗头部
.dialog-header {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-title {
  font-size: 15px;
  font-weight: 500;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: calc(100% - 40px);
}

// 统一的关闭按钮样式
%close-button {
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  border-radius: 50%;
  background-color: transparent;
  color: #999;

  &::before {
    content: '';
    display: block;
    width: 20px;
    height: 20px;
    mask-image: url($icon-close);
    -webkit-mask-image: url($icon-close);
    background-color: currentColor;
    mask-size: cover;
    -webkit-mask-size: cover;
    transition: transform 0.3s;
  }

  &:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #666;
    transform: rotate(90deg);
  }
}

// 应用统一样式
.dialog-close {
  @extend %close-button;
}

.message-close {
  @extend %close-button;
  width: 24px;
  height: 24px;

  &::before {
    width: 16px;
    height: 16px;
  }
}

.media-close {
  @extend %close-button;
  position: absolute;
  top: 16px;
  right: 16px;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  color: rgba(255, 255, 255, 0.9);

  &:hover {
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
  }
}

// 弹窗内容
.dialog-content {
  padding: 20px;
  font-size: 14px;
  line-height: 1.5;
  color: #666;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  word-wrap: break-word;
  word-break: break-all;
  max-height: 80vh;
  overflow-y: auto;

  .dialog-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    mask-size: contain;
    -webkit-mask-size: contain;
  }

  .dialog-message {
    flex-grow: 1;
    padding-top: 0;
    font-size: 15px;
    max-width: 100%;
    word-wrap: break-word;
    word-break: break-all;
  }

  // 不同类型的样式
  &.dialog-info {
    .dialog-icon {
      color: #2196f3;
    }
    .dialog-message {
      color: #2196f3;
    }
  }

  &.dialog-success {
    .dialog-icon {
      color: #4caf50;
    }
    .dialog-message {
      color: #4caf50;
    }
  }

  &.dialog-warning {
    .dialog-icon {
      color: #ff9800;
    }
    .dialog-message {
      color: #ff9800;
    }
  }

  &.dialog-error {
    .dialog-icon {
      color: #f44336;
    }
    .dialog-message {
      color: #f44336;
    }
  }

  // 媒体类型保持原样
  &.image, &.video {
    display: block;
    text-align: left;
    padding: 0;
    color: #fff;

    &::before {
      content: attr(data-error);
      display: none;
    }

    &.error::before {
      display: block;
      padding: 20px;
    }
  }
}

// 弹窗底部
.dialog-footer {
  padding: 12px 16px;
  border-top: 1px solid #eee;
  text-align: center;
}

// 按钮样式
.dialog-btn {
  min-width: 76px;
  height: 32px;
  padding: 0 12px;
  margin: 0 4px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  vertical-align: middle;

  &::before {
    width: 14px;
    height: 14px;
  }

  &.dialog-cancel {
    background: #f5f5f5;
    color: #666;

    &:hover {
      background: #e8e8e8;
    }
  }

  &.dialog-confirm {
    background: #2196f3;
    color: #fff;

    &:hover {
      background: #1976d2;
    }

    &:disabled {
      opacity: 0.7;
      cursor: not-allowed;
    }
  }
}

// 媒体弹窗样式
.dialog-wrapper {
  &.dialog-media {
    .media-close {
      position: absolute;
      top: 10px;
      right: 10px;
      width: 36px;
      height: 36px;
      line-height: 36px;
      text-align: center;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 50%;
      color: #fff;
      font-size: 24px;
      cursor: pointer;
      transition: all 0.3s;
      z-index: 1;
      display: flex;
      align-items: center;
      justify-content: center;

      &:hover {
        background: rgba(0, 0, 0, 0.7);
        transform: rotate(90deg);
      }
    }
  }
}

// 图片加载相关样式
.dialog-image-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 200px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;

  img {
    opacity: 0;
    transition: opacity 0.3s ease-out;
    will-change: opacity;
  }

  &.loaded {
    img {
      opacity: 1;
    }

    .dialog-image-loading {
      opacity: 0;
      visibility: hidden;
      transition: opacity 0.3s ease-out, visibility 0s 0.3s;
    }
  }

  &.error {
    .dialog-image-loading {
      opacity: 0;
      visibility: hidden;
    }
  }
}

.dialog-image-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: rgba(255, 255, 255, 0.9);
  transition: opacity 0.3s ease-out;
  will-change: opacity, visibility;

  .loading-icon {
    position: relative;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;

    &::before {
      content: '';
      position: absolute;
      width: 100%;
      height: 100%;
      border: 3px solid rgba(255, 255, 255, 0.1);
      border-top-color: #fff;
      border-radius: 50%;
      animation: rotate 1s linear infinite;
    }

    .material-icons {
      font-size: 24px;
      color: rgba(255, 255, 255, 0.9);
      animation: pulse 2s ease-in-out infinite;
    }
  }

  .loading-text {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 4px;

    span {
      display: inline-block;
      animation: wave 1.5s ease-in-out infinite;

      &:nth-child(2) { animation-delay: 0.1s; }
      &:nth-child(3) { animation-delay: 0.2s; }
    }
  }
}

// 修改媒体弹窗内容样式
.dialog-wrapper {
  &.dialog-media {
    .dialog-content {
      &.image {
        img {
          display: block;
          max-width: 100%;
          max-height: 95vh;
          margin: 0 auto;
          object-fit: contain;
        }
      }
    }
  }
}

// 消息提示框容器
.dialog-message-container {
  position: fixed;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: start;
  gap: 12px;
  padding: 16px;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  z-index: 2000;

  .message-wrapper {
    transform: translateY(-100%);
    opacity: 0;
  }

  &.message-show .message-wrapper {
    transform: translateY(0);
    opacity: 1;
  }
}

// 消息提示框
.message-wrapper {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  max-width: 90vw;
  width: max-content;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  margin-top: 0;
  position: relative;
  overflow: hidden;

  .message-icon {
    font-size: 20px;
    flex-shrink: 0;
  }

  .message-content {
    flex-grow: 1;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    max-width: 80vw;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }

  .message-close {
    font-size: 14px;
    color: #999;
    cursor: pointer;

    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;

    &:hover {
      color: #666;
    }
  }

  // 进度条
  .message-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background: rgba(0, 0, 0, 0.1);
    transform-origin: left;

    &::after {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: currentColor;
      transform: scaleX(0);
      transform-origin: left;
      transition: transform linear;
      transition-duration: var(--duration, 3000ms);
    }

    &.active::after {
      transform: scaleX(1);
    }
  }

  // 不同类型的样式
  &.message-info {
    border-left: 4px solid #2196f3;
    .message-icon {
      color: #2196f3;
    }
  }

  &.message-success {
    border-left: 4px solid #4caf50;
    .message-icon {
      color: #4caf50;
    }
  }

  &.message-warning {
    border-left: 4px solid #ff9800;
    .message-icon {
      color: #ff9800;
    }
  }

  &.message-error {
    border-left: 4px solid #f44336;
    .message-icon {
      color: #f44336;
    }
  }
}

// 图标样式
.dialog-icon, .message-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  background-color: currentColor;
  mask-size: cover;
  -webkit-mask-size: cover;
}

// 不同类型的图标
.dialog-info .dialog-icon, .message-info .message-icon {
  mask-image: url($icon-info);
  -webkit-mask-image: url($icon-info);
}

.dialog-success .dialog-icon, .message-success .message-icon {
  mask-image: url($icon-success);
  -webkit-mask-image: url($icon-success);
}

.dialog-warning .dialog-icon, .message-warning .message-icon {
  mask-image: url($icon-warning);
  -webkit-mask-image: url($icon-warning);
}

.dialog-error .dialog-icon, .message-error .message-icon {
  mask-image: url($icon-error);
  -webkit-mask-image: url($icon-error);
}

// 图片加载图标
.dialog-image-loading .loading-icon {
  width: 24px;
  height: 24px;
  mask-image: url($icon-image);
  -webkit-mask-image: url($icon-image);
  background-color: currentColor;
  mask-size: cover;
  -webkit-mask-size: cover;
}

// Loading 框样式
.dialog-loading {
  .dialog-wrapper {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 120px;
    width: auto !important;
    padding: 16px;
    border-radius: 8px;
  }

  .dialog-content {
    padding: 0;
    gap: 12px;
  }

  .loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2196f3;
    border-radius: 50%;
    animation: rotate 1s linear infinite;
  }

  .loading-text {
    color: #333;
    font-size: 14px;
    margin: 0;
  }
}

/* 加载状态样式 */
.loading-dot {
  display: inline-block;
  margin-right: 6px;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: loading-spin 0.8s linear infinite;
  vertical-align: middle;
  flex-shrink: 0;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

// 媒体导航按钮
.media-navigation {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none;
  z-index: 1;

  button {
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);

    &::before {
      content: '';
      display: block;
      width: 32px;
      height: 32px;
      background-color: currentColor;
      mask-size: contain;
      -webkit-mask-size: contain;
      mask-repeat: no-repeat;
      -webkit-mask-repeat: no-repeat;
      mask-position: center;
      -webkit-mask-position: center;
    }

    &:hover {
      background: rgba(0, 0, 0, 0.7);
    }

    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    &.media-prev::before {
      mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 18l-6-6 6-6'/%3E%3C/svg%3E");
      -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 18l-6-6 6-6'/%3E%3C/svg%3E");
    }

    &.media-next::before {
      mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18l6-6-6-6'/%3E%3C/svg%3E");
      -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18l6-6-6-6'/%3E%3C/svg%3E");
    }
  }
}

// 更新媒体容器样式
.dialog-media-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 200px;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;

  img, video {
    opacity: 0;
    transition: opacity 0.3s ease-out;
    will-change: opacity;
    max-width: 100%;
    max-height: 95vh;
    object-fit: contain;
  }

  &.loaded {
    img, video {
      opacity: 1;
    }

    .dialog-media-loading {
      opacity: 0;
      visibility: hidden;
      transition: opacity 0.3s ease-out, visibility 0s 0.3s;
    }
  }

  &.error {
    .dialog-media-loading {
      opacity: 0;
      visibility: hidden;
    }
  }
}

.dialog-media-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.8);

  .loading-icon {
    position: relative;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;

    &::before {
      content: '';
      position: absolute;
      width: 100%;
      height: 100%;
      border: 3px solid rgba(255, 255, 255, 0.1);
      border-top-color: #fff;
      border-radius: 50%;
      animation: rotate 1s linear infinite;
    }

    &::after {
      content: '';
      width: 24px;
      height: 24px;
      background-color: currentColor;
      mask-image: url($icon-image);
      -webkit-mask-image: url($icon-image);
      mask-size: contain;
      -webkit-mask-size: contain;
      animation: pulse 2s ease-in-out infinite;
    }
  }

  .loading-text {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 4px;

    span {
      display: inline-block;
      animation: wave 1.5s ease-in-out infinite;

      &:nth-child(2) { animation-delay: 0.1s; }
      &:nth-child(3) { animation-delay: 0.2s; }
    }
  }
}

// 媒体弹窗标题
.dialog-wrapper {
  &.dialog-media {
    .dialog-header {
      .dialog-title {
        max-width: calc(100% - 80px);
        opacity: 0.9;
      }
    }
  }
}